<?php if (!defined('THINK_PATH')) exit(); /*a:1:{s:28:"../template/admin\login.html";i:1529842191;}*/ ?>

<!DOCTYPE html>
<html lang="ZH-cn">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Login</title>
  <link rel="stylesheet" href="/blog/public/static/admin/layui/css/layui.css">
  <link rel="stylesheet" href="/blog/public/static/admin/layui/css/login.css">
  <script src= "/blog/public/static/admin/layui/js/jquery.min.js"></script>
  <script type="text/javascript">
    function refreshVerify() {
        var ts = Date.parse(new Date())/1000;
        $('#verify_img').attr("src", "../../captcha.html?id="+ts);
    }
  </script>
  
</head>

<body>
  <div class="kit-login">
    <div class="kit-login-bg"></div>
    <div class="kit-login-wapper">
      <h2 class="kit-login-slogan">欢迎登录 <br>Welcome</h2>
      <div class="kit-login-form">
        <h4 class="kit-login-title">登录</h4>
        <form class="layui-form">
          <div class="kit-login-row">
            <div class="kit-login-col">
              <i class="layui-icon">&#xe612;</i>
              <span class="kit-login-input">
                <input type="text" id="username" lay-verify="required" placeholder="用户名/邮箱/手机号" />
              </span>
            </div>
            <div class="kit-login-col"></div>
          </div>
          <div class="kit-login-row">
            <div class="kit-login-col">
              <i class="layui-icon">&#xe64c;</i>
              <span class="kit-login-input">
                <input type="password" id="password" lay-verify="required" placeholder="密码" />
              </span>
            </div>
            <div class="kit-login-col"></div>
          </div>
            <div class="kit-login-row">
            <div class="kit-login-col">
              <i class="layui-icon">&#xe679;</i>
              <span class="kit-login-input">
                <input type="text" id="verify" lay-verify="required" placeholder="验证码" />
              </span>
            </div><img src="<?php echo captcha_src(); ?>" alt="验证码" onclick="refreshVerify()" id="verify_img" />
            <div class="kit-login-col"></div>
          </div>

          <div class="kit-login-row">
            <div class="kit-login-col">
              <input type="checkbox" name="rememberMe" title="记住帐号" lay-skin="primary">
            </div>
          </div>
          <div class="kit-login-row">
            <button class="layui-btn kit-login-btn" lay-submit="submit" lay-filter="login_hash" id="submit">登录</button>
          </div>
        </form>
      </div>
    </div>
  </div>

<script src="/blog/public/static/admin/layui/layui.js"></script>
<script type="text/javascript">
    layui.use(['layer', 'form'], function() {
      var form = layui.form,
        $ = layui.jquery;
      //监听提交
      form.on('submit(login_hash)', function(data) {
        var username = $("#username").val();
        var password = $("#password").val();
        var verify = $("#verify").val();
        if (username == "" || password == "" || verify == "") {
            layer.msg('用户名密码或者验证码不能为空!');
        }else{
        $.ajax({
          type:"post",
          url:"usercheck",
          dataType:"json",
          data:{username:username,password:password,verify:verify},
          beforeSend: function () {
            // 禁用按钮防止重复提交
            $("#submit").attr({"disabled":"disabled"});
            $("#submit").addClass("layui-btn-disabled");
            $("#submit").html("登录中...");
            },
           error: function (XmlHttpRequest, textStatus, errorThrown) {
              if (XmlHttpRequest.responseText != "") {
                  layer.msg('登陆失败，请稍后尝试！');
                  $("#submit").removeClass("layui-btn-disabled");
                  $("#submit").removeAttr("disabled");  
                  $("#submit").html("登录");
              }
          },
          success:function(data){
            //1为验证码错误
            //2为用户名或者密码错误
            //3为登陆成功
            if (data.result == "1") {
              layer.msg(data.msg);
              $("#submit").removeClass("layui-btn-disabled");
              $("#submit").removeAttr("disabled");  
              $("#submit").html("登录");
              $("#password").val('');
              $("#verify").val('');
              refreshVerify()
            }else if(data.result == "2"){
              layer.msg(data.msg);
              $("#submit").removeClass("layui-btn-disabled");
              $("#submit").removeAttr("disabled");  
              $("#submit").html("登录");
              $("#password").val('');
              $("#verify").val('');
            }else{
              layer.msg(data.msg);
              setTimeout(function(){
                location.href=data.url;
              },1000);
            }
          }
        });
        }
        return false;
      });
    });
</script>
</body>

</html>